//
//  TTVisionView.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/20.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTVisionView.h"
#import <Masonry/Masonry.h>
#import "UIButton+TTButton.h"
@interface TTVisionView ()

@property (nonatomic,strong) UIImageView * scrollImage;
@property (nonatomic,strong) UIImageView * coverImage;
@property (nonatomic,strong) UIImageView * mainImage;
@property (nonatomic,strong) UILabel * homeLable;
@property (nonatomic,strong) UIButton * loginButton;
@property (nonatomic,strong) UIButton * regButton;

@end

@implementation TTVisionView

-(UIImageView *)scrollImage{
    
    if (_scrollImage == nil) {
        
        _scrollImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
        
    }
    
    return _scrollImage;
}

-(UIImageView *)coverImage{
    
    if (_coverImage == nil) {
        
        _coverImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    
    return _coverImage;
}

-(UIImageView *)mainImage{
    
    if (_mainImage == nil) {
        
        _mainImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
        
    }
    
    return _mainImage;
}

-(UILabel *)homeLable{
    
    if (_homeLable == nil) {
        
        _homeLable = [[UILabel alloc]init];
        _homeLable.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
        _homeLable.font = [UIFont systemFontOfSize:15];
        _homeLable.textAlignment = NSTextAlignmentCenter;
        _homeLable.numberOfLines = 0;
    }
    return _homeLable;
}

-(UIButton *)loginButton{
    
    if (_loginButton == nil) {
        
        _loginButton = [[UIButton alloc]init];
        
        [_loginButton getButtonWithtarget:self title:@"登录" img:@"common_button_white_disable" selector:@selector(didCenterButton:)];
    
    }
    return _loginButton;
}

-(UIButton *)regButton{
    
    if (_regButton == nil) {
        
        _regButton = [[UIButton alloc]init];
        [_regButton getButtonWithtarget:self title:@"注册" img:@"common_button_white_disable" selector:@selector(didCenterButton:)];
    }
    
    return _regButton;
}

-(void)didCenterButton:(UIButton*)sender{
    
    if ([self.delegate respondsToSelector:@selector(didCenterButton:and:)]) {
        
        [self.delegate didCenterButton:sender and:self];
    }
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setUpUI];
        [self setAnimation];
    }
    
    return self;
}

-(void)setAnimation{
    
    CABasicAnimation * anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    anima.toValue = @(M_PI * 2);
    
    anima.repeatCount = MAXFLOAT;
    anima.duration = 10;
    anima.removedOnCompletion = NO;
    [self.scrollImage.layer addAnimation:anima forKey:nil];
}

-(void)setUpUI{
    
    [self addSubview:self.scrollImage];
    [self addSubview:self.coverImage];
    [self addSubview:self.mainImage];
    [self addSubview:self.homeLable];
    [self addSubview:self.loginButton];
    [self addSubview:self.regButton];
    
    [self.scrollImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        
    }];
    
    [self.coverImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
    }];
    
    [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(self);
    }];
    
    [self.homeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.coverImage.mas_bottom).offset(16);
        make.width.equalTo(@240);
        make.height.equalTo(@36);
        make.centerX.equalTo(self.mas_centerX);
        
    }];
    
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.homeLable.mas_bottom).offset(16);
        make.width.equalTo(@100);
        make.height.equalTo(@36);
        make.leading.equalTo(self.homeLable);
    }];
    
    [self.regButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.homeLable.mas_bottom).offset(16);
        make.width.equalTo(@100);
        make.height.equalTo(@36);
        make.trailing.equalTo(self.homeLable);
    }];
}


-(void)setUpUIwith:(NSString*)title and:(NSString*)img{
    
    if (title != nil && img != nil) {
        
        self.mainImage.image = [UIImage imageNamed:img];
        self.homeLable.text = title;
        self.scrollImage.hidden = YES;
        
    }else{
        
        
    }
}

@end
